#!/bin/bash

# 检查是否传入了年份参数
if [ -z "$1" ]; then
  echo "Usage: $0 <year>"
  exit 1
fi

# 获取年份参数
year=$1

# 检查是否下载完毕
find /home/root/$year -type f -name '*.json.gz' | awk -F "/" '{print $NF}' | sed 's|^|https://data.gharchive.org/|' > tmp/download_$year.txt

cat urls/gharchive_urls_$year.txt | sort > tmp/a.txt

cat tmp/download_$year.txt | sort > tmp/b.txt

diff tmp/a.txt tmp/b.txt | grep '<' | awk -F '< ' '{print $2}' > tmp/not-download.txt

aria2c -x 10 -i tmp/not-download.txt --allow-overwrite -d /home/root/$year
